﻿@inject ContentService _contentService
@inject UserService _userService
@{
    var channels = new Channels[] { Channels.Content, Channels.Ask , Channels.Video};
    var categoryId = ViewContext.RouteData.Values["categoryId"].To<int>(0);
    var categories = await _contentService.GetCategoriesByParentAsync(0);
    var pageName = ViewContext.RouteData.Values["page"].ToString().ToLower();

    Channels? currentChannel = null;
    if (ViewContext.HttpContext.Request.Query["channel"].Any())
    {
        currentChannel = (Enum.Parse<Channels>(ViewContext.HttpContext.Request.Query["channel"].ToString(), true));

    }

}
<nav class="navbar navbar-expand-md bg-light mb-5 fixed-top">
    <a class="navbar-brand" href="/">
        <img src="~/images/logo.png" />
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav">
            <li class="nav-item @if (pageName.Contains("index")) {<text>active</text> }">
                <a asp-page="/Index" class="nav-link ">首页</a>
            </li>
            @foreach (var item in channels)
            {

            <li class="nav-item @if (currentChannel.HasValue && currentChannel == item) { <text>active</text>} ">
                <a asp-page="/Content/Index" asp-route-channel="@item" class="nav-link ">@(item.GetDescription())</a>
            </li>
            }
        </ul>
        <form class="form-inline  mx-auto" action="/Content/Search" target="_blank">
            <div class="input-group">
                <input class="form-control" name="keyword" value="@ViewContext.HttpContext.Request.Query["keyword"]" type="search" placeholder="输入关键字" aria-label="Search">
                <div class="input-group-append">
                    <button class="btn btn-dark" type="submit"><i class="fa fa-search"></i></button>
                </div>
            </div>
        </form>
        <ul class="navbar-nav">
            @if (User.Identity.IsAuthenticated)
            {
                <li class="nav-item"><a class="nav-link" asp-page="/User/Index" asp-route-userId="@User.Identity.UserId()"><img class="img-avatar-16 rounded" src="@User.Identity.UserAvatar()" /> @User.Identity.UserName()</a></li>
                @*<li class="nav-item"><a class="nav-link" asp-page="/Content/Edit" asp-route-id="" target="_blank"><i class="fa fa-edit"></i> 创作中心</a></li>*@
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-pencil-alt"></i></a>
                    <div class="dropdown-menu">
                        <a class="dropdown-item" asp-page="/Content/Edit" asp-route-id="" target="_blank">创作中心</a>
                        <a class="dropdown-item" asp-page="/Content/Edit" asp-route-channel="@Channels.Ask" asp-route-id="" target="_blank">有问必答</a>
                        <a class="dropdown-item" asp-page="/Content/Edit" asp-route-channel="@Channels.Video" asp-route-id="" target="_blank">多媒体视频</a>
                    </div>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-cogs"></i></a>
                    <div class="dropdown-menu">
                        <a class="dropdown-item" asp-page="/User/Setting/Information">个人资料</a>
                        <a class="dropdown-item" asp-page="/User/Setting/ChangeAvatar">更换头像</a>
                        <a class="dropdown-item" asp-page="/User/Setting/ChangePwd">修改密码</a>
                        <a class="dropdown-item" asp-page="/User/MySignIn">签到记录</a>
                    </div>
                </li>
                <li class="nav-item"><a class="nav-link" asp-page="/Account/Logout" title="退出"><i class="fa fa-sign-out-alt"></i></a></li>
            }
            else
            {
                <li class="nav-item"><a class="nav-link" asp-page="/Account/Login" asp-route-returnUrl="@ViewContext.HttpContext.Request.ToRelativeUrl()">登录</a></li>
                <li class="nav-item"><a class="nav-link" asp-page="/Account/Register">快速注册</a></li>
            }
        </ul>
    </div>

</nav>

